package br.inf.mfpo.fra4and.activities;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

/**
 * Activity simples, com extensões
 * 
 * @author MarcosFPo
 * 
 */
public abstract class Fra4AndActivity extends Activity {
	protected final String TAG = getClass().getSimpleName();

	/**
	 * Método a ser implementado para recuperar o estado da Activity
	 * 
	 * @param savedInstanceState
	 */
	protected abstract void restoreState(Bundle savedInstanceState);

	/**
	 * Método a ser implementado para salvar o estado da Activity
	 * 
	 * @param outState
	 */
	protected abstract void saveState(Bundle outState);

	/**
	 * Mostra um toast a partir de um resource id
	 * 
	 * @param stringId
	 */
	protected void showNotification(int stringId) {
		showNotification(getString(stringId));
	}

	/**
	 * Mostra um toast a partir de uma string
	 * 
	 * @param msg
	 */
	protected void showNotification(String msg) {
		Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
	}

	protected void showNotification(int stringId, int duration) {
		showNotification(getString(stringId), duration);
	}

	protected void showNotification(String msg, int duration) {
		Toast.makeText(getApplicationContext(), msg, duration).show();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d(TAG, "Creating " + TAG);
		restoreState(savedInstanceState);
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
		restoreState(savedInstanceState);
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		saveState(outState);
	}

}
